﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BasePlatformCommon;

namespace L9SubSet.WriteAddrPro
{
	public partial class Form_NewWriteAddrPro : Form
	{
		Form_WriteAddrPro parent = null;

		private string section = "NewWriteAddrPro";			// 多语言文件配置节名称

		private string tip = "提示";							// MessageBox 题头

		/*****************************************************************************************/

		// 构造函数
		public Form_NewWriteAddrPro(Form_WriteAddrPro parent)
		{
			InitializeComponent();

			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
			this.Font = new System.Drawing.Font(this.Font.Name, 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134)));

			this.parent = parent;
			
			// 设置本地化语言
			if (LanguageOper.available == true)
			{
				setLanguageText();
			}

            subNumTextBox.Text = parent.SubCount.ToString();
		}

		// 设置本地化语言
		public void setLanguageText()
		{
			if (LanguageOper.available == false)
			{
				return;
			}

			LanguageOper.SetCurrentCulture();

			tip = LanguageOper.ReadValue("Common", "tipStr");

			// 界面控件文字
			this.Text = LanguageOper.ReadValue(section, "newWriteAddrPro.Text");
			subNumLabel.Text = LanguageOper.ReadValue(section, "subNumLabel.Text");
			lampNumLabel.Text = LanguageOper.ReadValue(section, "lampNumLabel.Text");
			okButton.Text = LanguageOper.ReadValue(section, "okButton.Text");
			cancelButton.Text = LanguageOper.ReadValue(section, "cancelButton.Text");
			if (LanguageOper.LocalLanguage != LanguageEnum.EN)
			{
				subNumLabel.Location = new Point(39, 20);
				lampNumLabel.Location = new Point(27, 53);
			}
			else
			{
				subNumLabel.Location = new Point(45, 20);
				lampNumLabel.Location = new Point(10, 53);
			}
		}

		// 确定
		private void okButton_Click(object sender, EventArgs e)
		{
			int tmpSubNum = -1;
			int tmpLampNum = -1;

			bool res = int.TryParse(subNumTextBox.Text.ToString().Trim(), out tmpSubNum);
			if (res == false || tmpSubNum < 1 || tmpSubNum > 512)
			{
				string msg = "输入错误：分控数量应在 [1,512] 范围";
				if (LanguageOper.available == true)
				{
					msg = LanguageOper.ReadValue(section, "msgStr.0");
				}

				MessageBoxEx.Show(this, msg, tip, MessageBoxButtons.OK, MessageBoxIcon.Information);
				
				return;
			}

			res = int.TryParse(lampNumTextBox.Text.ToString().Trim(), out tmpLampNum);
			if (res == false || tmpLampNum < 0 || tmpLampNum > 512)
			{
				string msg = "输入错误：单分控带载灯数应在 [0,512] 范围";
				if (LanguageOper.available == true)
				{
					msg = LanguageOper.ReadValue(section, "msgStr.1");
				}

				MessageBoxEx.Show(this, msg, tip, MessageBoxButtons.OK, MessageBoxIcon.Information);
				
				return;
			}

			parent.subNum_new = tmpSubNum;
			parent.lampNum_new = tmpLampNum;

			this.DialogResult = System.Windows.Forms.DialogResult.OK;
		}

		// 取消
		private void cancelButton_Click(object sender, EventArgs e)
		{
			this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
		}
	}
}
